// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.advancedanimation;

import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import zombie.debug.DebugLog;
import zombie.debug.DebugType;

public final class AnimationSet {
    protected static final HashMap<String, AnimationSet> setMap = new HashMap();
    public final HashMap<String, AnimState> states = new HashMap();
    public String m_Name = "";

    public static AnimationSet GetAnimationSet(String name, boolean reload) {
        AnimationSet animationSet = (AnimationSet)setMap.get(name);
        if (animationSet != null && !reload) {
            return animationSet;
        } else {
            animationSet = new AnimationSet();
            animationSet.Load(name);
            setMap.put(name, animationSet);
            return animationSet;
        }
    }

    public static void Reset() {
        for (AnimationSet animationSet : setMap.values()) {
            animationSet.clear();
        }

        setMap.clear();
    }

    public AnimState GetState(String name) {
        AnimState animState = (AnimState)this.states.get(name.toLowerCase(Locale.ENGLISH));
        if (animState != null) {
            return animState;
        } else {
            DebugLog.Animation.warn("AnimState not found: " + name);
            return new AnimState();
        }
    }

    public boolean containsState(String name) {
        return this.states.containsKey(name.toLowerCase(Locale.ENGLISH));
    }

    public boolean Load(String name) {
        if (DebugLog.isEnabled(DebugType.Animation)) {
            DebugLog.Animation.println("Loading AnimSet: " + name);
        }

        this.m_Name = name;
        String[] string0 = zombie.ZomboidFileSystem.instance.resolveAllDirectories("media/AnimSets/" + name, var0 -> true, false);

        for (String string1 : string0) {
            String string2 = new File(string1).getName();
            AnimState animState = AnimState.Parse(string2, string1);
            animState.m_Set = this;
            this.states.put(string2, animState);
        }

        return true;
    }

    private void clear() {
        for (AnimState animState : this.states.values()) {
            animState.clear();
        }

        this.states.clear();
    }
}
